<?php

namespace App\Lib;

use GuzzleHttp\Client;

class ModelSdk
{
    public $client;

    public function __construct()
    {

        $this->client = new Client();
    }


    public function textToImage($lora, $keys, $width, $height, $secondCategory,$num)
    {
        log_daily('text-to-image')->info('request',['lora'=>$lora,'keys'=>$keys,'width'=>$width,'height'=>$height,'secondCategory'=>$secondCategory,'num'=>$num]);
        $client = new Client([
            'base_uri' => 'http://fu.maixiaotu.com:7860',
        ]);
        $resGet = $client->post("/sdapi/v1/txt2img/", [
            'json' => [
                "prompt" => "(masterpiece), (best quality),<lora:{$lora}:1>,{$secondCategory},$keys",
                "negative_prompt" => "paintings,sketches,(worst?quality:2),(low?quality:2),(normal?quality:2),lowres,normal?quality,((monochrome)),((grayscale)),skin?spots,wet,acnes,skin?blemishes,age?spot,(outdoor:1.6),manboobs,backlight,(ugly:1.331),(duplicate:1.331),(morbid:1.21),(mutilated:1.21),(tranny:1.331),mutated?hands,(poorly?drawn?hands:1.331),blurry,(bad?anatomy:1.21),(bad?proportions:1.331),extra?limbs,(disfigured:1.331),(more?than?2?nipples:1.331),(missing?arms:1.331),(extra?legs:1.331),(fused?fingers:1.61051),(too?many?fingers:1.61051),(unclear?eyes:1.331),lowers,bad?hands,missing?fingers,extra?digit,(futa:1.1),",
                "styles" => [
                    "string"
                ],
                "seed" => -1,
                "subseed" => -1,
                "subseed_strength" => 0,
                "seed_resize_from_h" => -1,
                "seed_resize_from_w" => -1,
                "sampler_name" => "DPM++ 2M Karras",
                "batch_size" => 1,
                "n_iter" => $num,
                "steps" => 20,
                "cfg_scale" => 7,
                "width" => $width,
                "height" => $height,
                "save_images" => true
            ],
            'verify' => false
        ]);
//        log_daily('text-to-image')->info('response',['res'=>$resGet->getBody()]);
        return json_decode($resGet->getBody(), true);
    }

    public function qianWen(){

    }

}
